package com.zxp.quartz.scheduler;

import com.zxp.quartz.job.MyJob1;
import com.zxp.quartz.job.MyJob2;
import com.zxp.quartz.job.MyJob4;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class MyScheduler {
	public static void main(String[] args) throws SchedulerException {

		Integer count = 0;
		// JobDetail
		JobDetail jobDetail = JobBuilder.newJob(MyJob2.class)
				.withIdentity("job1", "group1") // 名称需唯一
				.usingJobData("zxp","只为更好的你")
				.usingJobData("moon",5.21F)
				.usingJobData("name","jobDetail Name")
				.usingJobData("count1",count)
				.build();

		// Trigger
		Trigger trigger = TriggerBuilder.newTrigger()
				.withIdentity("trigger1", "group1")
				.usingJobData("zxp","triggerMoon")
				.usingJobData("name","triggerName")
				.usingJobData("count",count) // 统计任务执行的次数，需加注解
				.startNow()
				.withSchedule(SimpleScheduleBuilder.simpleSchedule()
						.withIntervalInSeconds(2)  // 隔2秒执行
						//.withRepeatCount(2)
						.repeatForever()
				)
				.build();

		// SchedulerFactory
		//SchedulerFactory  factory = new StdSchedulerFactory();
		//Scheduler scheduler = factory.getScheduler();

		Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

		// 绑定关系是1：N
		scheduler.scheduleJob(jobDetail, trigger);
		scheduler.start();
		
	}

}
